#ifndef _GAMEMODEL_H_
#define _GAMEMODEL_H_

#include <OpenThreads/Thread>
#include "boardstate.h"

enum MoveResult {
    CONTINUE = 0,
    WHITE_WIN,
    BLACK_WIN,
    DRAW
};

class AiThread : public OpenThreads::Thread
{
public:

    AiThread(BoardState& state, int depth);

    virtual void run();
    Move& getMove();
    bool isDone();

private:
    BoardState& _state;
    Move _move;
    bool _done;
    int _depth;
};

class GameModel
{
public:
    GameModel();
    ~GameModel();

	int getTurn();
	int getPiece(int x, int y);
	int getPieceColor(int piece);

	bool isMoveValid(int x0, int y0, int x1, int y1, int* moveId);
	MoveResult makeMove(const Move& move);

	Move getAiMove();

	const Move& getMove(int moveId);
	int getNumMoves();

    bool isPromotionMove(Move& move);
    const Move* getPromotionMove(SpecialRuleType promType, int x, int y);

	void startAiThread();
	bool isAiThreadStarted();

    // True if AI is not being calculated
    bool isReady();

    // Resets the model to the default state
    void reset();

    void setAiDepth(int depth);

private:
    BoardState _state;

    int nMoves;
    Move moveList[MAX_MOVES];

    AiThread* _thread;
    int _aiDepth;

};

#endif // _GAMEMODEL_H_
